/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.erp.server.DAO;

import com.erp.client.DAO.RzLogFind;
import com.erp.client.DAO.SeriaRzLog;
import com.erp.server.DB.DbConn;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class RzDao {


    public List<SeriaRzLog> getRzlogAll() throws SQLException {
        List<SeriaRzLog> rzlog = new ArrayList<SeriaRzLog>();
        String sql = "select  * from  rzlog order by recDate";
        Connection conn = DbConn.getCon();
        try {

            PreparedStatement ps = conn.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                SeriaRzLog u = new SeriaRzLog();
                u.setRzId(rs.getInt("rzID"));
                u.setEmpId(rs.getInt("EmpID"));
                u.setEmpName(rs.getString("EmpName"));
                u.setDepId(rs.getInt("DepID"));
                u.setDepName(rs.getString("DepName"));
                u.setRecDate(rs.getDate("recDate"));
                u.setWeek(rs.getString("Week"));
                u.setBeginTime(rs.getString("BeginTime"));
                u.setEndTime(rs.getString("EndTime"));
                u.setRecData(rs.getString("recData"));
                u.setInputDate(rs.getDate("InputDate"));
                u.setMangeId(rs.getInt("MangeID"));
                u.setMangeDemo(rs.getString("MangeDemo"));
                u.setMangeNumerical(rs.getDouble("MangeNumerical"));
                rzlog.add(u);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            conn.close();
        }
        return rzlog;
    }

    // 根据id查找用户
    public List<SeriaRzLog> getRzlogByrzid(int EmpID) throws SQLException {
        List<SeriaRzLog> rzlog = new ArrayList<SeriaRzLog>();
        String sql = "select * from rzlog where EmpID=? order by recDate";
        //System.out.print(EmpID);
        Connection conn = DbConn.getCon();
        try {

           PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, EmpID);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
                SeriaRzLog u = new SeriaRzLog();
                u.setRzId(rs.getInt("rzID"));
                u.setEmpId(rs.getInt("EmpID"));
                u.setEmpName(rs.getString("EmpName"));
                u.setDepId(rs.getInt("DepID"));
                u.setDepName(rs.getString("DepName"));
                u.setRecDate(rs.getDate("recDate"));
                u.setWeek(rs.getString("Week"));
                u.setBeginTime(rs.getString("BeginTime"));
                u.setEndTime(rs.getString("EndTime"));
                u.setRecData(rs.getString("recData"));
                u.setInputDate(rs.getDate("InputDate"));
                u.setMangeId(rs.getInt("MangeID"));
                u.setMangeDemo(rs.getString("MangeDemo"));
                u.setMangeNumerical(rs.getDouble("MangeNumerical"));
                rzlog.add(u);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            conn.close();
        }
        return rzlog;
    }
    
    public List<SeriaRzLog> getRzlogByDate(RzLogFind rzlogfind) throws SQLException {
        List<SeriaRzLog> rzlog = new ArrayList<SeriaRzLog>();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        //System.out.print(rzlogfind.getEmpId());
        //System.out.print(df.format(rzlogfind.getBeginDate()));
        //System.out.print(df.format(rzlogfind.getEndDate()));
        String sql = "select * from rzlog where EmpID=? and recDate >='"
                +df.format(rzlogfind.getBeginDate())
                +"'and recDate <='"+df.format(rzlogfind.getEndDate())+"' order by recDate";
        //System.out.print(EmpID);
        Connection conn = DbConn.getCon();
        try {

           PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, rzlogfind.getEmpId());
           
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
                SeriaRzLog u = new SeriaRzLog();
                u.setRzId(rs.getInt("rzID"));
                u.setEmpId(rs.getInt("EmpID"));
                u.setEmpName(rs.getString("EmpName"));
                u.setDepId(rs.getInt("DepID"));
                u.setDepName(rs.getString("DepName"));
                u.setRecDate(rs.getDate("recDate"));
                u.setWeek(rs.getString("Week"));
                u.setBeginTime(rs.getString("BeginTime"));
                u.setEndTime(rs.getString("EndTime"));
                u.setRecData(rs.getString("recData"));
                u.setInputDate(rs.getDate("InputDate"));
                u.setMangeId(rs.getInt("MangeID"));
                u.setMangeDemo(rs.getString("MangeDemo"));
                u.setMangeNumerical(rs.getDouble("MangeNumerical"));
                rzlog.add(u);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            conn.close();
        }
        return rzlog;
    }
}
